/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nus.application.web.base;

import com.nus.application.web.base.annotation.SessionInject;
import com.nus.application.web.base.context.ParameterBean;
import com.nus.constant.ConstantSystemParam;
import com.nus.dataaccess.dao.user.UserAccount;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Locale;
import java.util.Map;
import org.apache.struts2.ServletActionContext;

import javax.servlet.ServletContext;
import org.apache.struts2.interceptor.SessionAware;

/**
 *
 * @author robin.foe
 */
public class BaseAction extends ActionSupport implements ServletRequestAware, SessionAware{

    public static final String EVENT_LIST = "list";
    public static final String EVENT_CREATE = "create";
    public static final String EVENT_MAINTAIN = "maintain";
    public static final String EVENT_SAVE = "save";
    public static final String EVENT_FLASH = "flash";    
    public static final String EVENT_PROCESSED = "processed";    
    
    public String actionValue;
    public String[] previousPath;
    public String[] currentPath;
    public String actionResult;
    public static ParameterBean getParameterBean(ServletContext application, HttpServletRequest request)
    {
            ParameterBean sc = (ParameterBean) application.getAttribute(ParameterBean.class.getName());
            if (sc == null)
            {
                    sc = ParameterBean.initiateParemeterBean(application);
                    application.setAttribute(ParameterBean.class.getName(), sc);
            }
            return sc;
    }

    public String getRedirectUrl(){return this.getActionResult();}
    public String getActionValue() {return actionValue;}
    public void setActionValue(String actionValue) {this.actionValue = actionValue;}

    public String[] getPreviousPath() {return previousPath;}
    public void setPreviousPath(String[] previousPath) {this.previousPath = previousPath;}

    public String[] getCurrentPath() {return currentPath;}
    public void setCurrentPath(String[] currentPath) {this.currentPath = currentPath;}

    public String getActionResult() {return actionResult;}
    public void setActionResult(String actionResult) {this.actionResult = actionResult;}

    public HttpServletRequest getServletRequest(){return ServletActionContext.getRequest();}
    public static Locale getCurrentLocale(){return Locale.ENGLISH;}
    
    private String formEvent;
    public String getFormEvent() {return formEvent;}
    public void setFormEvent(String formEvent) {this.formEvent = formEvent;}
    public boolean isSaveEvent(){return BaseAction.EVENT_SAVE.equals(this.formEvent);}
    public boolean isListEvent(){return BaseAction.EVENT_LIST.equals(this.formEvent);}
    public boolean isProcessedEvent(){return BaseAction.EVENT_PROCESSED.equals(this.formEvent);}

    public static String applicationName;
    public static String webDocumentRoot;
    public String getApplicationName() {
    //		if(UtilityBean.isEmpty(applicationName)){
    //			applicationName = getParameterBean(application, request)
    //		}
            return applicationName;
    }

    public String getWebDocumentRoot() {return webDocumentRoot;}

    private HttpServletRequest request;
    public HttpServletRequest getRequest() {return request;}
    public void setServletRequest(HttpServletRequest request) {this.request = request;}
    
    private int page = 1;
    public int getPage() {return page;}
    public void setPage(int page) {this.page = page;}
    
    protected Map<String, Object> session;
    public void setSession(Map<String, Object> session) {this.session = session;}
	

    @SessionInject(sessionId=ConstantSystemParam.SESSION,autoCreate=false)
    private UserAccount userAccount;
    public UserAccount getCurrentLoginUser(){return userAccount;}
	
//	public Date getCurrentTimestamp(){return UtilityBean.getSystemDate();}

        
    
}
